/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FormPessoa.java
 *
 * Created on 17/03/2011, 19:39:26
 */

package Interface;

import Interface.Combos.Itens;
import Modelo.ConexaoBD;
import java.io.FileInputStream;
import java.sql.*;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import javax.swing.JButton;

/**
 * Form para cadastro de formulários
 * @author Jonas Gualberto Diel [jonasdiel@gmail.com]
 */
public class FormRespostas extends javax.swing.JInternalFrame {

    public static Connection con;
    public static Statement stmt;
    private static String FUNCTION;

    private int questionCategoryId; //Chave primária da tabela
    
    /** Creates new form FormPessoa */
    public FormRespostas() {
        abreConexao();
        initComponents();
        preparaComboBoxFormulario();
    }

    //Abre uma conexão com o banco de dados
    private void abreConexao() {
        try {
            con = ConexaoBD.getInstance().getConnection();
            stmt = con.createStatement();
        } catch (Exception e) {
            System.out.print(e);
        }
    }

    public void preparaComboBoxFormulario()
    {
        // Populando as combos
        Combos cmb = new Combos("rshForm");
        Map<String, Itens> m = cmb.getMap();
        formId.removeAllItems(); // limpa Combo        
        formId.addItem("::Selecione::"); // Preenche a primeira opcao
        Set<String> chaves = m.keySet();
        Iterator<String> it = chaves.iterator();
        while (it.hasNext()) {
        String chave = it.next();
        formId.addItem(chave);
        
        }
    }
    

    /**
     * @param aFUNCTION the FUNCTION to set
     */
    public static void setFunction(String aFUNCTION) {
        FUNCTION = aFUNCTION;
    }

     /**
     * @return the FUNCTION
     */
    public static String getFunction() {
        return FUNCTION;
    }

    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnGerar = new javax.swing.JButton();
        validaFormId = new javax.swing.JLabel();
        labelFormId = new javax.swing.JLabel();
        formId = new javax.swing.JComboBox();

        setBorder(javax.swing.BorderFactory.createEtchedBorder());
        setClosable(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        setIconifiable(true);
        setTitle("Cadastrar respostas");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setName("FormRelatorio"); // NOI18N

        btnGerar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Interface/imagens/save_as.png"))); // NOI18N
        btnGerar.setText("Gerar");
        btnGerar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGerarActionPerformed(evt);
            }
        });

        validaFormId.setForeground(new java.awt.Color(255, 0, 0));

        labelFormId.setText("Formulário:");

        formId.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        formId.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                formIdActionPerformed(evt);
            }
        });
        formId.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                formIdKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnGerar)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(labelFormId)
                        .addGap(59, 59, 59)
                        .addComponent(formId, 0, 277, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(validaFormId, javax.swing.GroupLayout.PREFERRED_SIZE, 194, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(30, 30, 30))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(validaFormId, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(labelFormId)
                        .addComponent(formId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 64, Short.MAX_VALUE)
                .addComponent(btnGerar)
                .addGap(19, 19, 19))
        );

        getAccessibleContext().setAccessibleName("");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnGerarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGerarActionPerformed
        
        String fileQuestionario = "";
        
        //Validação dos campos
        if( true )
        {
            try {
                //Carrega as informaçoes do relatorios
                Properties prop = new Properties();            
                prop.load(new FileInputStream("REPORTS.properties"));
                fileQuestionario = prop.getProperty("report.questionario.path");
            } 
            catch (Exception e) 
            {
                System.err.println(e);
            }
            
//            if( questionario.getSelectedItem() == "Questionário")
//            {
//               
//                //Obtem valor da combo de formulario
//                Combos cmbForm = new Combos("rshForm");
//                Map<String, Itens> mForm = cmbForm.getMap();
//                Itens dataForm = mForm.get(formId.getSelectedItem());
//                
//                //Cria os parametros para geracao            
//                Parameters[] parametros = new Parameters[1];
//                parametros[0] = new Parameters();
//                parametros[0].var = "formId";
//                parametros[0].value = dataForm.getCodigo();            
//                //gera o relatorio
//                Relatorio rel = new Relatorio(fileQuestionario, con, parametros);                
//                rel.gerar();
//            }
        }
    }//GEN-LAST:event_btnGerarActionPerformed

    
    private void formIdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_formIdActionPerformed
        
        //Evento de selecionar um formulário cria os campos necessarios conforme as opcoes selecionadas
       
        
}//GEN-LAST:event_formIdActionPerformed

    private void formIdKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formIdKeyPressed
        
}//GEN-LAST:event_formIdKeyPressed


    @Override
    public void setDefaultCloseOperation(int operation) {

        
        super.setDefaultCloseOperation(operation);
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnGerar;
    private javax.swing.JComboBox formId;
    private javax.swing.JLabel labelFormId;
    private javax.swing.JLabel validaFormId;
    // End of variables declaration//GEN-END:variables

}
